<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUserTiersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_tiers', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id');
            $table->string('tier_name', 100)->comment('Social Seed, Dialogue Explorer等');
            $table->unsignedTinyInteger('tier_level')->comment('段位等级数字');
            $table->unsignedInteger('experience_points')->default(0);
            $table->timestamp('tier_achieved_at')->useCurrent();
            $table->boolean('is_current')->default(true);
            
            // 外键约束
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            
            // 索引
            $table->index(['user_id']);
            $table->index(['is_current']);
            $table->index(['tier_level']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_tiers');
    }
}